define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'banner/index' + location.search,
                    add_url: 'banner/add',
                    edit_url: 'banner/edit',
                    del_url: 'banner/del',
                    multi_url: 'banner/multi',
                    table: 'banner',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'sort',
                sortOrder: 'desc',
                pageSize: 10,
                pageList: [10, 25, 50, 100],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true, visible: true},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible: true},
                        {field: 'admin_nickname', title: __('Publisher'), operate: 'LIKE'},
                        {field: 'link_product_id', title: __('Link Product ID'), operate: 'LIKE'},
                        {field: 'sort', title: __('Sort'), sortable: true},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Disabled'),"1":__('Enabled')}, formatter: function (value, row, index) {
                            return value == 1 ? '<span class="text-success"><i class="fa fa-circle"></i> ' + __('Enabled') + '</span>' : '<span class="text-gray"><i class="fa fa-circle"></i> ' + __('Disabled') + '</span>';
                        }},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                            {
                                name: 'edit',
                                text: __('编辑'),
                                icon: 'fa fa-pencil',
                                classname: 'btn btn-xs btn-success btn-editone'
                            },
                            {
                                name: 'del',
                                text: __('删除'),
                                icon: 'fa fa-trash',
                                classname: 'btn btn-xs btn-danger btn-delone'
                            }
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($('form[role="form"]'));
            }
        }
    };
    return Controller;
});